#define _CRT_SECURE_NO_WARNINGS

class Solution {
public:
    int monotoneIncreasingDigits(int n) {
        string s = to_string(n);
        int flag = s.size();
        for (int i = s.size() - 1; i > 0; i--)
        {
            if (s[i] < s[i - 1])
            {
                s[i - 1]--;
                flag = i;
            }
        }
        for (int i = flag; i < s.size(); i++)
            s[i] = '9';
        return stoi(s);
    }
};

class Solution {
public:
    int _CameraCoverR(TreeNode* root, int& ret)
    {
        if (root == nullptr)
            return 2;
        int left = _CameraCoverR(root->left, ret);
        int right = _CameraCoverR(root->right, ret);
        if (left == 2 && right == 2)
            return 0;
        if (left == 0 || right == 0)
        {
            ret++;
            return 1;
        }
        if (left == 1 || right == 1)
            return 2;
        return 0;
    }
    int minCameraCover(TreeNode* root) {
        int ret = 0;
        if (_CameraCoverR(root, ret) == 0)
            ret++;
        return ret;
    }
};